package com.x.ant.dao;

import com.x.ant.model.Province;
import com.x.ant.model.City;
import com.x.ant.model.District;
import com.x.framework.dao.BaseDao;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class AreaDao extends BaseDao {
    private final static String selectProvinceListSql = "SELECT t1.* FROM BASE_PROVINCE t1 WHERE t1.PROVINCE_STATE = 1 ORDER BY t1.PROVINCE_CODE";
    public List<Province> selectProvinceList(Province province) throws Exception{
        return this.queryForList(selectProvinceListSql, Province.class);
    }

    private final static String selectCitytListSql = "SELECT t1.* FROM BASE_CITY t1 WHERE t1.CITY_STATE = 1 AND t1.PROVINCE_ID = ? ORDER BY t1.CITY_CODE";
    public List<City> selectCitytList(City city) throws Exception{
        Object[] params = {city.getProvinceId()};
        return this.queryForList(selectCitytListSql, City.class, params);
    }

    private final static String selectDistrictListSql = "SELECT t1.* FROM BASE_DISTRICT t1 WHERE t1.DISTRICT_STATE = 1 AND t1.CITY_ID = ? ORDER BY t1.DISTRICT_CODE";
    public List<District> selectDistrictList(District district) throws Exception{
        Object[] params = {district.getCityId()};
        return this.queryForList(selectDistrictListSql, District.class, params);
    }

}
